import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import CLIPSJNI.Environment;


/* Implement FindFact which returns just a FactAddressValue or null */
/* TBD Add size method to PrimitiveValue */

class HistorialAcademico extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = 2942074537775707298L;

    JLabel dLabel;

    JComboBox promedioArte;
    JComboBox promedioLengua;
    JComboBox promedioNaturales;
    JComboBox promedioSociales;
    JComboBox promedioMatematica;


    JButton nextButton;
    JButton prevButton;
    JPanel choicesPanel;
    ButtonGroup choicesButtons;
    
	
	PrintWriter writer;

    Environment clips;

    public HistorialAcademico()  {

        /* ================================ */
        /* Create a new JFrame container. */
        /* ================================ */

        final JFrame jfrm = new JFrame("TestVocacionalDemo");


        /* ============================= */
        /* Specify FlowLayout manager. */
        /* ============================= */

        jfrm.getContentPane().setLayout(new GridLayout(1, 1));

        /* ================================= */
        /* Give the frame an initial size. */
        /* ================================= */

        jfrm.setSize(750, 300);
        jfrm.setLocation(200, 100);

        /* ============================================================= */
        /* Terminate the program when the user closes the application. */
        /* ============================================================= */

        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        /* =========================== */
        /* Create the display panel. */
        /* =========================== */

        JPanel displayPanel = new JPanel();
        JLabel displayLabel = new JLabel();
        displayPanel.add(displayLabel);
        
       
        /* =========================== */
        /* Create the choices panel. */
        /* =========================== */

        choicesPanel = new JPanel();
        choicesPanel.setBorder(BorderFactory.createTitledBorder("Historial académico del alumno"));
             
        choicesPanel.setSize(400, 400);
        choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS));
        
		dLabel = new JLabel("Promedio en materias de Arte");
        choicesPanel.add(dLabel);
        promedioArte = new JComboBox();
        promedioArte.addItem("1");
        promedioArte.addItem("2");
        promedioArte.addItem("3");
		promedioArte.addItem("4");
		promedioArte.addItem("5");
		promedioArte.addItem("6");
		promedioArte.addItem("7");
		promedioArte.addItem("8");
		promedioArte.addItem("9");
		promedioArte.addItem("10");
		
        choicesPanel.add(promedioArte);

        dLabel = new JLabel("Promedio en materias de Lenguas");
        choicesPanel.add(dLabel);
        promedioLengua = new JComboBox();
		promedioLengua.addItem("1");
        promedioLengua.addItem("2");
        promedioLengua.addItem("3");
		promedioLengua.addItem("4");
		promedioLengua.addItem("5");
		promedioLengua.addItem("6");
		promedioLengua.addItem("7");
		promedioLengua.addItem("8");
		promedioLengua.addItem("9");
		promedioLengua.addItem("10");
		
        choicesPanel.add(promedioLengua);

        dLabel = new JLabel("Promedio en Ciencias Naturales");
        choicesPanel.add(dLabel);
        promedioNaturales = new JComboBox();
		promedioNaturales.addItem("1");
        promedioNaturales.addItem("2");
        promedioNaturales.addItem("3");
		promedioNaturales.addItem("4");
		promedioNaturales.addItem("5");
		promedioNaturales.addItem("6");
		promedioNaturales.addItem("7");
		promedioNaturales.addItem("8");
		promedioNaturales.addItem("9");
		promedioNaturales.addItem("10");
        choicesPanel.add(promedioNaturales);

        dLabel = new JLabel("Promedio en Ciencias Sociales");
        choicesPanel.add(dLabel);
        promedioSociales = new JComboBox();
		promedioSociales.addItem("1");
        promedioSociales.addItem("2");
        promedioSociales.addItem("3");
		promedioSociales.addItem("4");
		promedioSociales.addItem("5");
		promedioSociales.addItem("6");
		promedioSociales.addItem("7");
		promedioSociales.addItem("8");
		promedioSociales.addItem("9");
		promedioSociales.addItem("10");
        choicesPanel.add(promedioSociales);
		
		

        dLabel = new JLabel("Promedio en Matematica");
        choicesPanel.add(dLabel);
        promedioMatematica = new JComboBox();
		promedioMatematica.addItem("1");
        promedioMatematica.addItem("2");
        promedioMatematica.addItem("3");
		promedioMatematica.addItem("4");
		promedioMatematica.addItem("5");
		promedioMatematica.addItem("6");
		promedioMatematica.addItem("7");
		promedioMatematica.addItem("8");
		promedioMatematica.addItem("9");
		promedioMatematica.addItem("10");
        choicesPanel.add(promedioMatematica);

       

        /* =========================== */
        /* Create the buttons panel. */
        /* =========================== */

        
        try {
            writer = new PrintWriter("factsPromedios.clp", "UTF-8");

        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        JPanel buttonPanel = new JPanel();



        nextButton = new JButton("Next");
        nextButton.setActionCommand("Next");
        choicesPanel.add(nextButton);
        nextButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
				ConocimientosPrevios conocimientoPanel = new ConocimientosPrevios();
                writer.println("(deffacts caso_2 " );
				writer.println("	(historial_academico " );
				writer.println("		(promedio_arte "+promedioArte.getSelectedItem().toString()+")");
				writer.println("		(promedio_lengua "+promedioLengua.getSelectedItem().toString()+")");
				writer.println("		(promedio_naturales "+promedioNaturales.getSelectedItem().toString()+")" );
				writer.println("		(promedio_sociales "+promedioSociales.getSelectedItem().toString()+")");
				writer.println("		(promedio_matematica "+promedioMatematica.getSelectedItem().toString()+")))");
				writer.close();
				
				
				conocimientoPanel.setVisible(true);
                jfrm.setVisible(false);

				

            }
        });

        /* ===================================== */
        /* Add the panels to the content pane. */
        /* ===================================== */

        jfrm.getContentPane().add(displayPanel);
        jfrm.getContentPane().add(choicesPanel);
        jfrm.getContentPane().add(buttonPanel);

        /* ==================== */
        /* Display the frame. */
        /* ==================== */

        jfrm.setVisible(true);
        displayLabel.setText("Run clips file");
        /* ================================== */
        /* Get the current state of the UI. */
        /* ================================== */

    }


}
